package com.simon.mengkou.ui.view;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.simon.mengkou.R;
import com.simon.mengkou.data.enums.ELevel;
import com.simon.mengkou.system.global.OuerApplication;

/**
 * Created by xiazhenshui on 16/6/12.
 */

public class AvatarSimpleDraweeView extends LinearLayout {
    private SimpleDraweeView mSdvAvatar;
    private ImageView mIvCrown;

    public AvatarSimpleDraweeView(Context context) {
        super(context);
        init(context);
    }

    public AvatarSimpleDraweeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public AvatarSimpleDraweeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    public AvatarSimpleDraweeView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context) {
        setOrientation(LinearLayout.VERTICAL);
        setGravity(Gravity.CENTER);

        View view = LayoutInflater.from(context).inflate(R.layout.layout_avatar, null);
        mSdvAvatar = (SimpleDraweeView) view.findViewById(R.id.user_id_avatar);
        mIvCrown = (ImageView) view.findViewById(R.id.user_id_crown);
        LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        addView(view, params);
    }

    /**
     *
     */
    public void loadAvatar(String url, int level) {
        OuerApplication.mImageLoader.loadAvatar(mSdvAvatar, url);

        if(level == ELevel.STAR) {
           mIvCrown.setVisibility(View.VISIBLE);
        } else {
            mIvCrown.setVisibility(View.GONE);
        }
    }
}
